<?php

namespace addons\tools\model;

use think\Model;

class UserVip extends Model
{
    protected $name = 'user_vip';

    protected $autoWriteTimestamp = true;

    public function meal()
    {
        return $this->belongsTo(Meal::class, 'meal_id', 'id');
    }

    public function getValidityTimeAttr($value)
    {
        return $value ? date('Y-m-d', $value) : $value;
    }

    protected $append = [
        'is_vip'
    ];

    public function getIsVipAttr($value, $data)
    {

        if ($data['validity_time'] && $data['validity_time'] >= time())
            return true;
        return false;
    }
}